package com.eptok.weixin.filter;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class GzipJsFilter implements Filter   
{   
Map headers = new HashMap();   
  
public void destroy() { }   
  
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)throws IOException, ServletException {   
    if (req instanceof HttpServletRequest)   
      doFilter((HttpServletRequest)req, (HttpServletResponse)res, chain);   
    else  
      chain.doFilter(req, res);   
}   
  
public void doFilter(HttpServletRequest request, HttpServletResponse response,FilterChain chain)   
    throws IOException, ServletException   
{   
    request.setCharacterEncoding("UTF-8");   
    for (Iterator it = this.headers.entrySet().iterator(); it.hasNext(); ) {   
      Map.Entry entry = (Map.Entry)it.next();   
      response.addHeader((String)entry.getKey(), (String)entry.getValue());   
    }   
    chain.doFilter(request, response);   
}   
  
public void init(FilterConfig config) throws ServletException {   
    String headersStr = config.getInitParameter("headers");   
    String[] headers = headersStr.split(",");   
    for (int i = 0; i < headers.length; ++i) {   
      String[] temp = headers[i].split("=");   
      this.headers.put(temp[0].trim(), temp[1].trim());   
    } 
    
    System.out.println("                    _ooOoo_                    "); 
	System.out.println("                   o8888888o                   ");
	System.out.println("                   88\" . \"88                   ");
	System.out.println("                   (| -_- |)                   ");
	System.out.println("                   O\\  =  /O                   ");
	System.out.println("                ____/`---'\\____                ");
	System.out.println("              .'  \\\\|     |//  `.              ");
	System.out.println("             /  \\\\|||  :  |||//  \\             ");
	System.out.println("            /  _||||| -:- |||||-  \\            ");
	System.out.println("            |   | \\\\\\  -  /// |   |            ");
	System.out.println("            | \\_|  ''\\---/''  |   |            ");
	System.out.println("            \\  .-\\__  `-`  ___/-. /	           ");
	System.out.println("          ___`. .'  /--.--\\  `. . __           ");
	System.out.println("       .\"\" '<  `.___\\_<|>_/___.'  >'\"\".        ");
	System.out.println("      | | :  `- \\`.;`\\ _ /`;.`/ - ` : | |      ");
	System.out.println("      \\  \\ `-.   \\_ __\\ /__ _/   .-` /  /      ");
	System.out.println(" ======`-.____`-.___\\_____/___.-`____.-'====== ");
	System.out.println(" 		    `=---='                     ");
	System.out.println(" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ");
    
}   
} 